package cc.lucien.Controller;

import cc.lucien.entity2.Address;
import cc.lucien.entity2.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lucien-ma
 * @date 2021/9/8
 * @apiNote
 */
@Controller
@RequestMapping("/student")
public class StudentHandler {

    @GetMapping("/get")
    public String get(Model model) {
        Student student = new Student();
        student.setId(1);
        student.setName("张三");
        student.setPassword("5269");
        student.setAge(22);
        student.setGender("男");
        Address address = new Address(1, "科技路");
        student.setAddress(address);
        student.setFlag(true);
        student.setHobby(Arrays.asList("读书", "看电影", "打游戏","旅行","听音乐","散步"));
        student.setSelectHobby(Arrays.asList("打游戏", "看电影", "读书"));
        student.setRadioId(1);
        Map<Integer, String> gradeMap = new HashMap<>();
        gradeMap.put(1, "一年级");
        gradeMap.put(2, "二年级");
        gradeMap.put(3, "三年级");
        gradeMap.put(4, "四年级");
        gradeMap.put(5, "五年级");
        gradeMap.put(6, "六年级");
        student.setGradeMap(gradeMap);
        student.setSelectGrade(3);
        Map<Integer, String> cityMap = new HashMap<>();
        cityMap.put(1, "北京");
        cityMap.put(2, "上海");
        cityMap.put(3, "深圳");
        cityMap.put(4, "杭州");
        student.setCityMap(cityMap);
        student.setSelectCity(2);
        model.addAttribute("student", student);
        return "student2";
    }

    @PostMapping("/update")
    public String update(Student student) {
        System.out.println(student);
        return "student2";
    }
}
